package com.ssyc.student.activity;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.netease.nim.uikit.business.recent.RecentContactsFragment;
import com.netease.nim.uikit.common.activity.UI;
import com.ssyc.common.base.BaseActivity;
import com.ssyc.common.utils.UiUtils;
import com.ssyc.student.R;


/**
 * 学生单--消息界面
 * Created by Administrator on 2018/5/16 0016.
 */

public class StudentMessageActivity extends BaseActivity implements View.OnClickListener {
    //返回
    private ImageView ivBack;

    //通讯录
    private ImageView ivAddressBook;

    //放置云信会话列表Fragment的布局
    private LinearLayout llMessage;

    //网易云信的会话列表Framgent
    private RecentContactsFragment fragment;

    @Override
    protected boolean isNeedShowTitle() {
        return false;
    }

    @Override
    protected String setTitleText() {
        return null;
    }

    @Override
    protected int getContentLayout() {
        return R.layout.student_activity_message;
    }

    @Override
    protected void init() {

        showContent();

        initView();

        //动态添加会话列表
        addRecentContactsFragment();
    }

    /**
     * 初始化View
     */
    public void initView() {
        ivBack = findViewById(R.id.iv_back);
        ivBack.setOnClickListener(this);
        ivAddressBook = findViewById(R.id.iv_address_book);
        ivAddressBook.setOnClickListener(this);
        llMessage = findViewById(R.id.ll_message);
    }

    /**
     * 动态添加网易云信会话列表的Fragment
     */
    private void addRecentContactsFragment() {
        fragment = new RecentContactsFragment();
        // 设置要集成联系人列表fragment的布局文件
        fragment.setContainerId(R.id.ll_message);

        final UI activity = this;

        // 如果是activity从堆栈恢复，FM中已经存在恢复而来的fragment，此时会使用恢复来的，而new出来这个会被丢弃掉
        fragment = (RecentContactsFragment) activity.addFragment(fragment);
    }


    /**
     * 页面控件点击事件
     *
     * @param v
     */
    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.iv_back) {
            //返回
            finish();
        } else if (id == R.id.iv_address_book) {
            //跳转到通讯录界面
            UiUtils.startActivity(this, StudentAddressBookActivity.class);
        }
    }

}
